<?php
App::uses('AppModel', 'Model');
App::uses('BrValidation', 'Localized.Validation');
/**
 * Empresa Model
 *
 * @property Endereco $Endereco
 */
class Empresa extends AppModel {

	var $name = 'Empresa';
	public $useTable = 'empresas';
	//var $order = array("Empresa.created" => "DESC");
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'nome' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Campo nome deve ser preenchido',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'cnpj' => array(
			 'valid' => array(
				'rule' => array('ssn', null, 'br'),
				'message' => 'Digite um CNPJ válido!',
				'allowEmpty' => false,
				'required' => true,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			), 
		),
		 'telefone' => array(
			'valid' => array(
				'rule' => array('phone', null, 'br'),
				'message' => 'Digite o número do telefone corretamente!',
				'allowEmpty' => false,
				'required' => true,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),  
		'email' => array(
			'email' => array(
				'rule' => array('email'),
				'message' => 'Informe um email válido',
				'allowEmpty' => false,
				'required' => true,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'site' => array(
			'url' => array(
				'rule' => array('url'),
				'message' => 'Digite um endereço web válido!',
				'allowEmpty' => false,
				'required' => true,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'representante' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => true,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongTo associations
 *
 * @var array
 */
	public $belongTo = array(
		'Endereco' => array(
			'className' => 'Endereco',
			'foreignKey' => 'endereco_id',
			'conditions' => array('Endereco.id' => 'Empresa.endereco_id'),
			'fields' => '',
			'order' => ''
		)
	);
}
